package laf.behaviours;

import java.util.Collection;
import java.util.Set;

import com.sun.crypto.provider.DESCipher;

import jade.core.behaviours.OneShotBehaviour;
import laf.agents.CognitiveAgent;
import laf.agents.LanguageSymbolDictionary;
import laf.env.AttributeValue;
import laf.env.Observation;
import laf.lang.Describes;
import laf.lang.Symbol;

public class BroadcastObservationBehaviour extends OneShotBehaviour {
	
	protected CognitiveAgent cognitiveAgent;
	protected Observation observation;
	
	public BroadcastObservationBehaviour(CognitiveAgent agent, Observation observation) {
		super(agent);
		cognitiveAgent = agent;
		this.observation = observation;
	}

	@Override
	public void action() {
		Set<AttributeValue> attrVals = observation.getValues().getValues();
		LanguageSymbolDictionary dict = cognitiveAgent.getDictionary();
		Collection<Symbol> correlatedSymbols = dict.findCorrelatedSymbols(attrVals, cognitiveAgent.getCorrelationLevel(), cognitiveAgent.getCredibilityLevel());
		Describes description;
		for (Symbol symbol : correlatedSymbols) {
			description = new Describes();
			description.setTime(observation.getTime());
			description.setObjectIdentifier(observation.getObjectIdentifier());
			description.setSymbol(symbol);
			cognitiveAgent.addBehaviour(new BroadcastDescriptionBehaviour(cognitiveAgent, description));
		}
	}
}
